<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const p1 = new Promise((resolve,reject)=>{
      try {
        throw new Error('制造错误')
        setTimeout(()=>{
          resolve('ok')
        },2000)
      } catch (error) {
        reject(error.message)
      }
    })

    // const p1 = new Promise((resolve, reject) => {
    //   console.log("开始请求数据.......")
    //   try {
    //     // throw new Error("请求数据网络错误~~~~")
    //     //使用定时器模拟ajax请求
    //     setTimeout(() => {
    //       console.log("数据请求成功!!!!");
    //       resolve("okk")
    //     }, 2000)
    //   } catch (e) {
    //     //catch接收的e就是错误对象
    //     console.log(e);
    //     //e上有一个message属性,就是当前错误的信息
    //     console.log(e.message);
    //     reject(e.message)
    //   }
    // })

    console.log("p1", p1)
  </script>
</body>

</html>